

package com.hazelcast.config;

import static java.util.Arrays.copyOf;

/**
 * Contains configuration for symmetric encryption
 *
 * @deprecated since 4.2
 */
@Deprecated
public class SymmetricEncryptionConfig extends AbstractSymmetricEncryptionConfig<SymmetricEncryptionConfig> {

    /**
     * Default symmetric encryption algorithm
     */
    public static final String DEFAULT_SYMMETRIC_ALGORITHM = "PBEWithMD5AndDES";

    /**
     * Default symmetric encryption password used in Hazelcast before version 5.5.
     */
    public static final String DEFAULT_SYMMETRIC_PASSWORD = "thepassword";

    private static final int DEFAULT_ITERATION_COUNT = 19;

    private int iterationCount = DEFAULT_ITERATION_COUNT;
    private String password;
    private byte[] key;

    public SymmetricEncryptionConfig() {
        algorithm = DEFAULT_SYMMETRIC_ALGORITHM;
    }

    public String getPassword() {
        return password;
    }

    public SymmetricEncryptionConfig setPassword(String password) {
        this.password = password;
        return this;
    }

    public int getIterationCount() {
        return iterationCount;
    }

    public SymmetricEncryptionConfig setIterationCount(int iterationCount) {
        this.iterationCount = iterationCount;
        return this;
    }

    public byte[] getKey() {
        return cloneKey(key);
    }

    public SymmetricEncryptionConfig setKey(byte[] key) {
        this.key = cloneKey(key);
        return this;
    }

    private byte[] cloneKey(byte[] key) {
        return key != null ? copyOf(key, key.length) : null;
    }

    @Override
    public String toString() {
        return "SymmetricEncryptionConfig{" + "enabled=" + enabled + ", algorithm='" + algorithm + '\'' + ", password='***'" + ", salt='***'" + ", iterationCount=***" + ", key=***" + '}';
    }
}
